<template>
	<view>
		<view class="time">
			{{ date | timeFormat }}
		</view>

		<view class="qr">
			<image src="../../static/logo.png" mode="" class="icon-header"></image>
			<view class="name">
				{{ name }}
			</view>
			<view class="position">
				{{ position }}
			</view>
			<view class="icon">
				<image src="../../static/iconapp.png" mode="" class="qr-code"></image>
			</view>
		</view>
		
		<view class="icon-history">
			<view class="tit" @click="gosignhistory">
				历史记录
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				date: ''
			}
		},
		created() {
			this.inittime()
			setInterval(() => {
				this.inittime()
			}, 1000)
		},
		computed: {
			name() {
				return this.$store.state.userInfo.username
			},
			position() {
				if (this.$store.state.userInfo.role === 1) return 'Student'
				if (this.$store.state.userInfo.role === 2) return 'Teacher'
				if (this.$store.state.userInfo.role === 3) return 'Super Manager'
			}
		},
		methods: {
			inittime() {
				this.date = new Date()
			},
			gosignhistory(){
				uni.navigateTo({
					url:'/pages/signhistory/signhistory'
				})
			}
		},
		filters: {
			timeFormat(date) {
				var y = date.getFullYear()
				var m = padzero(date.getMonth() + 1)
				var d = padzero(date.getDate())
				var h = padzero(date.getHours())
				var mm = padzero(date.getMinutes())
				var s = padzero(date.getSeconds())
				return y + '年' + m + '月' + d + '日' + h + '时' + mm + '分' + s + '秒'
			}
		}
	}

	function padzero(n) {
		return n > 9 ? n : '0' + n
	}
</script>

<style lang="less">
	page {
		background-color: #f8f9f9;
	}

	.time {
		margin-top: 50rpx;
		text-align: center;
		font-size: 40rpx;
	}

	.qr {
		position: relative;
		width: 65%;
		height: 750rpx;
		margin: 150rpx auto 0;
		box-sizing: border-box;
		border-radius: 15rpx;
		background-color: #fff;

		.icon-header {
			position: absolute;
			left: 50%;
			top: 0;
			transform: translate(-50%, -50%);
			width: 130rpx;
			height: 130rpx;
			border-radius: 50%;
		}

		.name {
			position: absolute;
			top: 90rpx;
			left: 50%;
			transform: translateX(-50%);
			font-size: 40rpx;
		}

		.position {
			position: absolute;
			top: 150rpx;
			left: 50%;
			transform: translateX(-50%);
			color: #999;
		}

		.icon {
			position: absolute;
			left: 50%;
			bottom: 60rpx;
			transform: translateX(-50%);
			width: 90%;
			height: 487rpx;
			background-color: #F5F5F5;

			.qr-code {
				position: absolute;
				left: 0;
				top: 0;
				width: 100%;
				height: 100%;
			}
		}
	}
	.icon-history {
		width: 130rpx;
		height: 130rpx;
		margin: 20rpx auto 0;
		font-size: 70rpx;
		text-align: center;
		line-height: 55rpx;
		padding-top: 15rpx;
		box-sizing: border-box;
		color: #555;
		background-color: #fff;
		border-radius: 50%;
		.tit {
			font-size: 25rpx;
		}
	}
</style>
